package jUnitTestSuite;

public class ShoppingCart
{
	private Product[] container;
	
	public ShoppingCart( int size )
	{
		container = new Product[ size ];
	}
	
	public boolean addItem( Product p )
	{
		int i = 0;
		
		// insert
		while( i < container.length )
		{
			if( container[ i ] == null )
			{
				container[ i ] = p;
				return true;
			}
			i++;
		}
		// or throw out
		p = null;
		return false;
	}
	
	public Product removeItem( int index )
	{
		// modify length to be within cart
		index = index % container.length;
		Product p = container[ index ];
		container[ index ] = null;
		return p;
	}
	
	public Product inspectItem( int index )
	{
		// modify length to be within cart
		index = index % container.length;
		return container[ index ];
	}
	
	public double returnCost()
	{
		double cost = 0;
		
		for( int i = 0; i < container.length; i++ )
		{
			cost += container[i].getPrice();
		}
		return cost;
	}
}
